﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.MediaCenter;
using Microsoft.MediaCenter.Hosting;
using Microsoft.MediaCenter.UI;
using System.Diagnostics;
using MediaLibraryManager;

namespace MediaLibraryManager.MediaCenter
{
	public class MediaLibraryManagerPlugin: ModelItem
	{
		private static MediaLibraryManagerPlugin singleApplicationInstance;
		private AddInHost host;
		private HistoryOrientedPageSession session;

		public MediaLibraryManagerPlugin()
			: this(null, null)
		{
		}

		public MediaLibraryManagerPlugin(HistoryOrientedPageSession session, AddInHost host)
		{
			this.session = session;
			this.host = host;
			singleApplicationInstance = this;
		}

		public MediaCenterEnvironment MediaCenterEnvironment
		{
			get
			{
				if (host == null) return null;
				return host.MediaCenterEnvironment;
			}
		}

		public void GoToOption(string option)
		{
			Dictionary<string, object> properties = new Dictionary<string, object>();
			properties["MediaLibraryManagerPlugin"] = this;

			if (session != null)
			{
				session.GoToPage(
					String.Format("resx://MediaLibraryManager.MediaCenter/MediaLibraryManager.MediaCenter.Resources/{0}",
						option),
					properties);
			}
			else
			{
				Debug.WriteLine("GoToOption");
			}
		}

		public IEnumerable<MusicVideo> GetMusicVideos()
		{
			MediaLibraryDataContext db = new MediaLibraryDataContext();

			IEnumerable<MusicVideo> result =	from p in db.MusicVideos
												select p;

			return result;
		}
	}
}
